import { Entity, model, property, belongsTo, hasMany } from '@loopback/repository';
import { User } from './user.model';
import { Comment } from './comment.model';

/**
 * 帖子
 */
@model()
export class Post extends Entity {
  @property({
    type: 'number',
    id: true,
  })
  id: number;

  // @property({
  //   type: 'number',
  //   required: true,
  // })

  @belongsTo(() => User)
  userId: number;

  @property({
    type: 'string',
    required: true,
  })
  content: string;

  @property({
    type: 'array',
    itemType: 'string',
  })
  images?: string[];

  // @hasMany(() => Comment)
  // comments?: Comment[];

  @property({
    type: 'number',
    required: true,
    default: 0,
  })
  starCount: number;

  @property({
    type: 'number',
    required: true,
    default: 0,
  })
  likeCount?: number;

  @property({
    type: 'date',
  })
  created?: string;

  constructor(data?: Partial<Post>) {
    super(data);
  }
}
